<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script src="lib/http.js"></script>
    <style>
        #loading{
            position: fixed;
            top:0;bottom: 0;
            left:0;right:0;
            display: flex;
            justify-content: center;
            align-items: center;
            background: #fff;
        }
        #app{
            display:flex;
            flex-wrap: wrap;
            justify-content:space-between
        }
    </style>
</head>
<body>
    <div id="loading">
        <img src="images/loading.gif" alt="">
    </div>
    <div id="app"></div>
    <script>
        var start=0
        http({
            data:{start},
            callback:handleData
        })
        function handleData(res){
            var subjects=res.subjects
            var movies=[]
            for(i=0;i<subjects.length;i++){
                var obj={}
                obj.title=subjects[i].title
                obj.imageUrl=subjects[i].images.small
                movies.push(obj)
            }
            for (var j = 0; j < movies.length; j++) {
                var item = $(`<div class="item"><img src="${movies[j].imageUrl}"/><p>${movies[j].title}</p></div>`)
                $("#app").append(item)
            }
            $(window).scroll(function(){
                if(onReachBottom()){
                    start+=20;
                    http({
                        data:{start},
                        callback:handleData
                    })
                }
            })
        }
    </script>
</body>
</html>